<script>
import {Menu,Message,Setting,House,Flag,Opportunity} from "@element-plus/icons-vue";
// import {icon}
export default {
  name: "Aside",
  components:{
    Menu,
    Message,
    Setting,
    House,
    Flag,
    Opportunity
  },
  props: {
    isCollapse: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      activeIndex: '/Home'
    }
  },
  methods: {
    handleMenuSelect(index) {
      this.activeIndex = index;
      console.log('选择菜单:', index);
    }
  }
}
</script>

<template>
<!--  <el-scrollbar>-->
<!--    <el-menu :default-openeds="['1', '3']">-->
<!--      <el-sub-menu index="1">-->
<!--        <template #title>-->
<!--          <el-icon><message /></el-icon>Navigator One-->
<!--        </template>-->
<!--        <el-menu-item-group>-->
<!--          <template #title>Group 1</template>-->
<!--          <el-menu-item index="1-1">Option 1</el-menu-item>-->
<!--          <el-menu-item index="1-2">Option 2</el-menu-item>-->
<!--        </el-menu-item-group>-->
<!--        <el-menu-item-group title="Group 2">-->
<!--          <el-menu-item index="1-3">Option 3</el-menu-item>-->
<!--        </el-menu-item-group>-->
<!--        <el-sub-menu index="1-4">-->
<!--          <template #title>Option4</template>-->
<!--          <el-menu-item index="1-4-1">Option 4-1</el-menu-item>-->
<!--        </el-sub-menu>-->
<!--      </el-sub-menu>-->
<!--      <el-sub-menu index="2">-->
<!--        <template #title>-->
<!--          <el-icon><Menu /></el-icon>Navigator Two-->
<!--        </template>-->
<!--        <el-menu-item-group>-->
<!--          <template #title>Group 1</template>-->
<!--          <el-menu-item index="2-1">Option 1</el-menu-item>-->
<!--          <el-menu-item index="2-2">Option 2</el-menu-item>-->
<!--        </el-menu-item-group>-->
<!--        <el-menu-item-group title="Group 2">-->
<!--          <el-menu-item index="2-3">Option 3</el-menu-item>-->
<!--        </el-menu-item-group>-->
<!--        <el-sub-menu index="2-4">-->
<!--          <template #title>Option 4</template>-->
<!--          <el-menu-item index="2-4-1">Option 4-1</el-menu-item>-->
<!--        </el-sub-menu>-->
<!--      </el-sub-menu>-->
<!--      <el-sub-menu index="3">-->
<!--        <template #title>-->
<!--          <el-icon><setting/></el-icon>Navigator Three-->
<!--        </template>-->
<!--        <el-menu-item-group>-->
<!--          <template #title>Group 1</template>-->
<!--          <el-menu-item index="3-1">Option 1</el-menu-item>-->
<!--          <el-menu-item index="3-2">Option 2</el-menu-item>-->
<!--        </el-menu-item-group>-->
<!--        <el-menu-item-group title="Group 2">-->
<!--          <el-menu-item index="3-3">Option 3</el-menu-item>-->
<!--        </el-menu-item-group>-->
<!--        <el-sub-menu index="3-4">-->
<!--          <template #title>Option 4</template>-->
<!--          <el-menu-item index="3-4-1">Option 4-1</el-menu-item>-->
<!--        </el-sub-menu>-->
<!--      </el-sub-menu>-->
<!--    </el-menu>-->
<!--  </el-scrollbar>-->
  <div class="sidebar-wrapper">
    <div class="sidebar-header" v-if="!isCollapse">
      <div class="logo-section">
        <div class="logo-icon">
          <el-icon><House /></el-icon>
        </div>
        <span class="logo-text">仓库管理</span>
      </div>
    </div>
    
    <el-menu
      :default-active="activeIndex"
      class="sidebar-menu"
      :collapse="isCollapse"
      :collapse-transition="true"
      background-color="transparent"
      text-color="#333"
      active-text-color="#409EFF"
      @select="handleMenuSelect"
    >
      <el-menu-item index="/Home" class="menu-item">
        <el-icon class="menu-icon"><House /></el-icon>
        <span class="menu-text">首页</span>
      </el-menu-item>
      
      <el-menu-item index="/One" class="menu-item">
        <el-icon class="menu-icon"><Flag /></el-icon>
        <span class="menu-text">库存管理</span>
      </el-menu-item>
      
      <el-menu-item index="/Two" class="menu-item">
        <el-icon class="menu-icon"><Opportunity /></el-icon>
        <span class="menu-text">出入库</span>
      </el-menu-item>
      
      <el-menu-item index="/Three" class="menu-item">
        <el-icon class="menu-icon"><Message /></el-icon>
        <span class="menu-text">报表统计</span>
      </el-menu-item>
      
      <el-menu-item index="/Four" class="menu-item">
        <el-icon class="menu-icon"><Setting /></el-icon>
        <span class="menu-text">系统设置</span>
      </el-menu-item>
    </el-menu>
    
    <div class="sidebar-footer" v-if="!isCollapse">
      <div class="user-info">
        <el-avatar :size="40" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
        <div class="user-details">
          <div class="user-name">胡xx</div>
          <div class="user-role">管理员</div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.sidebar-wrapper {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: transparent;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #409EFF, #67C23A);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
}

.logo-text {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  letter-spacing: 1px;
}

.sidebar-menu {
  flex: 1;
  border: none;
  background: transparent !important;
  padding: 20px 0;
}

.menu-item {
  margin: 8px 16px;
  border-radius: 12px;
  transition: all 0.3s ease;
  height: 50px;
  line-height: 50px;
}

.menu-item:hover {
  background: rgba(64, 158, 255, 0.1) !important;
  transform: translateX(4px);
}

.menu-item.is-active {
  background: rgba(64, 158, 255, 0.15) !important;
  border-right: 3px solid #409EFF;
  color: #409EFF !important;
}

.menu-icon {
  font-size: 18px;
  margin-right: 12px;
  transition: all 0.3s ease;
}

.menu-item:hover .menu-icon {
  transform: scale(1.1);
}

.menu-text {
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
}

.user-info:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

.user-details {
  flex: 1;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 2px;
}

.user-role {
  font-size: 12px;
  color: #666;
}

/* 收缩状态下的样式 */
:deep(.el-menu--collapse) {
  width: 64px;
}

:deep(.el-menu--collapse .el-menu-item) {
  text-align: center;
  padding: 0 20px;
}

:deep(.el-menu--collapse .el-menu-item .menu-icon) {
  margin-right: 0;
}

/* 菜单项在收缩状态下的tooltip */
:deep(.el-menu--collapse .el-tooltip) {
  padding: 0 20px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .sidebar-header {
    padding: 15px;
  }
  
  .logo-text {
    font-size: 16px;
  }
  
  .menu-item {
    margin: 6px 12px;
    height: 45px;
    line-height: 45px;
  }
  
  .menu-icon {
    font-size: 16px;
  }
  
  .menu-text {
    font-size: 13px;
  }
  
  .sidebar-footer {
    padding: 15px;
  }
}

/* 动画效果 */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.menu-item {
  animation: slideIn 0.3s ease-out;
}

.menu-item:nth-child(1) { animation-delay: 0.1s; }
.menu-item:nth-child(2) { animation-delay: 0.2s; }
.menu-item:nth-child(3) { animation-delay: 0.3s; }
.menu-item:nth-child(4) { animation-delay: 0.4s; }
.menu-item:nth-child(5) { animation-delay: 0.5s; }
</style>
